package com.bill99.rpc.config.spring.schema;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import com.bill99.rpc.protocol.hessian.HessianProtocolBean;

/**
 * @author sheng.zhang
 */
public class HessianProtocolBeanDefinationParser extends
		AbstractRpcBeanDefinationParser {

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	protected Class<?> getBeanClass(Element element) {
		return HessianProtocolBean.class;
	}

	@Override
	protected String resolveId(Element element,
			AbstractBeanDefinition definition, ParserContext parserContext)
			throws BeanDefinitionStoreException {
		return element.getAttribute("path");
	}

	@Override
	protected void doParse(Element element, ParserContext parserContext,
			BeanDefinitionBuilder builder) {
		logger.info("to parse hessian protocol configuration");
		String name = element.getAttribute("name");
		if (name != null && name.trim().length() > 0)
			builder.addPropertyValue("name", name);
		String path = element.getAttribute("path");
		if (path != null && path.trim().length() > 0)
			builder.addPropertyValue("path", path);
	}

}
